import agconnect from '@hw-agconnect/api-ohos'
import '@hw-agconnect/core-ohos'
import '@hw-agconnect/auth-ohos'
import '@hw-agconnect/function-ohos'

interface Card {
  amount: number
  bank: string
  cardNumber: string
  ccv: string
  expiredAt: string
  name: string
  uuid: string
}

export const addUser = async (payload: {
  uuid: string,
  name: string,
  email: string,
  phone: string,
  avatar: string
}) => {
  const functionCallable = agconnect.function().wrap('user-$latest')
  const result = await functionCallable.call({
    action: 'add',
    payload
  })

  return result.getValue()
}

/**
 * 添加银行卡
 */
export const addBackCard = async (payload: {
  uuid: string,
  bank: string,
  name: string,
  cardNumber: string,
  expiredAt: string,
  ccv: string
}): Promise<{
  status: boolean,
  errMsg?: string
}> => {
  const functionCallable = agconnect.function().wrap("add-card-$latest")
  const result = await functionCallable.call({
    // 操作类型 新增还是删除等等
    action: 'add',
    payload
  })

  return result.getValue()
}

export const queryBackCard = async (payload: {
  uuid: string
}): Promise<{
  data: Card[]
}> => {
  const functionCallable = agconnect.function().wrap("add-card-$latest")

  const result = await functionCallable.call({
    // 操作类型 新增还是删除等等
    action: 'query',
    payload
  })
  return result.getValue()
}